package com.connector.base.connection.session;

import com.connector.base.connection.SessionContext;

public final class ResuableSession
{
    private String sessionId;
    private long expireTime;
    private SessionContext context;
    
    public static String encode(final SessionContext context) {
        final StringBuffer sb = new StringBuffer();
        sb.append(context.getOsName()).append(',');
        sb.append(context.getOsVersion()).append(',');
        sb.append(context.getClientVersion()).append(',');
        sb.append(context.getDeviceId()).append(',');
        return sb.toString();
    }
    
    public static ResuableSession decode(final String value) {
        final String[] array = value.split(",");
        if (array.length != 4) {
            return null;
        }
        final SessionContext context = new SessionContext();
        context.setOsName(array[0]);
        context.setOsVersion(array[1]);
        context.setClientVersion(array[2]);
        context.setDeviceId(array[3]);
        final ResuableSession session = new ResuableSession();
        session.context = context;
        return session;
    }
    
    public String getSessionId() {
        return this.sessionId;
    }
    
    public long getExpireTime() {
        return this.expireTime;
    }
    
    public SessionContext getContext() {
        return this.context;
    }
    
    public void setSessionId(final String sessionId) {
        this.sessionId = sessionId;
    }
    
    public void setExpireTime(final long expireTime) {
        this.expireTime = expireTime;
    }
    
    public void setContext(final SessionContext context) {
        this.context = context;
    }
}
